﻿using Gds.ViewModel.pageViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Gas_Server_framework.PageView
{
    /// <summary>
    /// ViewConfig.xaml 的交互逻辑
    /// </summary>
    public partial class ViewConfig : Window
    {
        public ViewConfig()
        {
            InitializeComponent();
            init();
            this.DataContext = ServerConfigViewModel.Instance;

        }
        private void init()
        {
            ServerConfigViewModel.Instance.Init();
        }
        private void btn_showResult_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("是否主服务器:" + ServerConfigViewModel.Instance.LocalConfig.IsMainServer.ToString());
        }

        private void btn_save_Click(object sender, RoutedEventArgs e)
        {
            ServerConfigViewModel.Instance.SaveLocalConfig();
            MessageBox.Show("save success");
        }

        private void btn_delhis_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int delMaxTime = int.Parse(txt_dataSaveMaxDay.Text);
                Task.Factory.StartNew(() =>
                {
                    MainViewModel.Instance.DeleteHistoryData(delMaxTime);

                });

            }
            catch (Exception ex)
            { 
            
            }
        }

        private void btn_changeO2State_Click(object sender, RoutedEventArgs e)
        {
            MainViewModel.Instance.ChangeAutoO2State((bool)chk_IsO2defaultOk.IsChecked);
        }
    }
}
